<!DOCTYPE html>
<html>
<head>
<%include("../../tpl/head_jqgrid.html"){}%>
<title>后台管理-角色管理</title>
<link href="http://cdn.bootcss.com/zTree.v3/3.5.24/css/metroStyle/metroStyle.min.css" rel="stylesheet">
</head>
<body class="hold-transition fixed skin-blue sidebar-mini">
	<div class="wrapper">
		<!-- 头部 -->
		<%include("../../tpl/header.html",{menus:menus}){}%>
		<!-- 网页正文 -->
		<div class="content-wrapper">
			<!-- 网页正文-面包屑 -->
			<div class="content-header">
				<h1>角色管理</h1>
				<ol class="breadcrumb">
					<li><a href="/admin/index.jspx"><i class="fa fa-dashboard"></i> 后台系统</a></li>
					<li><a href="#">用户管理</a></li>
					<li class="active">角色管理</li>
				</ol>
			</div>
			<!-- 网页正文-主体 -->
			<section class="content">
				<table id="jqGrid"></table>
				<div id="jqGridPager"></div>
			</section>
			<!-- /.content -->
		</div>
		<!-- 网页底部 -->
		<%include("../../tpl/footer.html"){}%>
	</div>
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">配置权限</h4>
				</div>
				<div class="modal-body">
					<ul id="zTree" class="ztree"></ul>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" id="save_role_btn">保存</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<%include("../../tpl/script_jqgrid.html"){}%>
	<script src="http://cdn.bootcss.com/zTree.v3/3.5.24/js/jquery.ztree.all.min.js"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			var setting = {
				view : {
					selectedMulti : false
				},
				check : {
					enable : true
				},
				data : {
					simpleData : {
						enable : true
					}
				}
			};
			$("#save_role_btn").on('click', function() {
				var $modal = $('#myModal');
				var treeObj = $.fn.zTree.getZTreeObj("zTree");
				var nodes = treeObj.getCheckedNodes();
				var param = {
					role : $modal.data('role'),
					ids : []
				};
				for ( var tmp in nodes) {
					param.ids.push(nodes[tmp].id);
				}
				Ajax.json('permission/save.json', param, function(result) {
					$modal.modal('hide');
				});
			})
			jqGrid.init({
				page : '${page!1}',
				colModel : [ {
					label : 'ID',
					name : 'id',
					key : true
				}, {
					label : '角色名称',
					name : 'name',
					editable : true
				}, {
					label : '标示',
					name : 'identity',
					editable : true
				} ],
				ondblClickRow : function(rowid, iRow, iCol, e) {
					Ajax.post('permission/list.json', {
						id : rowid
					}, function(result) {
						$.fn.zTree.destroy();
						var ztree = $.fn.zTree.init($("#zTree"), setting, result.data);
						var $modal = $('#myModal');
						$modal.data('role', rowid);
						$modal.modal('show');
					})
				}
			});
			jqGrid.initNav();
		});
	</script>
</body>
</html>
